package com.example.certificate.controller;

import com.example.certificate.annoatiton.LoginToken;
import com.example.certificate.dto.InsDataTypeDto;
import com.example.certificate.dto.UpdateStatusDTO;
import com.example.certificate.dto.common.BasePageDataPageDto;
import com.example.certificate.dto.common.DelByIdDto;
import com.example.certificate.entity.DataType;
import com.example.certificate.mapper.DataTypeMapper;
import com.example.certificate.service.DataTypeService;
import com.example.certificate.utils.ResultEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hao
 * @since 2022-03-08 11:01:39
 */
@RestController
@RequestMapping("/domain/dataType")
public class DataTypeController {

    @Autowired
    private DataTypeService dataTypeService;

    @Resource
    private DataTypeMapper dataTypeMapper;

    @LoginToken
    @ApiOperation("修改数据状态")
    @PostMapping(value = "/updateStatus")
    public ResultEntity updateStatus(@RequestBody UpdateStatusDTO dto){
        return dataTypeService.updateStatus(dto);
    }


    @LoginToken
    @ApiOperation(value = "分页多条件查询数据类型")
    @PostMapping(value = "/selDataTypePage")
    public ResultEntity selDataTypePage(@RequestBody BasePageDataPageDto dto){
        return dataTypeService.selDataTypePage(dto);
    }


    @LoginToken
    @ApiOperation(value = "查询引导页")
    @PostMapping(value = "/selDataTypeList")
    public ResultEntity selDataTypeList(){
        return dataTypeService.selDataTypeList();
    }

    @LoginToken
    @ApiOperation(value = "新增作品画风风格")
    @PostMapping(value = "/insertDataType")
    public ResultEntity insertDataType(@RequestBody InsDataTypeDto dto){
        return dataTypeService.insertDataType(dto);
    }

    @LoginToken
    @PostMapping(value = "/delDataTypeById")
    @ApiOperation(value = "删除作品画风风格")
    public ResultEntity delDataTypeById(@Validated(value = {DelByIdDto.delDataById.class}) @RequestBody DelByIdDto dto){
        return dataTypeService.delDataTypeById(dto);
    }


    @PostMapping(value = "/productLists")
    @ApiOperation(value = "获取作品画风风格列表")
    public ResultEntity productLists(){
        List<DataType> dataTypes = dataTypeMapper.selByList();
        return new ResultEntity(dataTypes);
    }
}

